package com.tudouji.project.handover.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.handover.domain.HandoverOrder;
import com.tudouji.project.handover.service.IHandoverOrderService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 工作交接单Controller
 * 
 * @author tudouji
 * @date 2022-06-20
 */
@RestController
@RequestMapping("/handover/order")
public class HandoverOrderController extends BaseController
{
    @Autowired
    private IHandoverOrderService handoverOrderService;

    /**
     * 查询工作交接单列表
     */
    @PreAuthorize("@ss.hasPermi('handover:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(HandoverOrder handoverOrder)
    {
        startPage();
        List<HandoverOrder> list = handoverOrderService.selectHandoverOrderList(handoverOrder);
        return getDataTable(list);
    }

    /**
     * 导出工作交接单列表
     */
    @PreAuthorize("@ss.hasPermi('handover:order:export')")
    @Log(title = "工作交接单", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(HandoverOrder handoverOrder)
    {
        List<HandoverOrder> list = handoverOrderService.selectHandoverOrderList(handoverOrder);
        ExcelUtil<HandoverOrder> util = new ExcelUtil<HandoverOrder>(HandoverOrder.class);
        return util.exportExcel(list, "order");
    }

    /**
     * 获取工作交接单详细信息
     */
    @PreAuthorize("@ss.hasPermi('handover:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(handoverOrderService.selectHandoverOrderById(id));
    }

    /**
     * 新增工作交接单
     */
    @PreAuthorize("@ss.hasPermi('handover:order:add')")
    @Log(title = "工作交接单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HandoverOrder handoverOrder)
    {
        return toAjax(handoverOrderService.insertHandoverOrder(handoverOrder));
    }

    /**
     * 修改工作交接单
     */
    @PreAuthorize("@ss.hasPermi('handover:order:edit')")
    @Log(title = "工作交接单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HandoverOrder handoverOrder)
    {
        return toAjax(handoverOrderService.updateHandoverOrder(handoverOrder));
    }

    /**
     * 删除工作交接单
     */
    @PreAuthorize("@ss.hasPermi('handover:order:remove')")
    @Log(title = "工作交接单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(handoverOrderService.deleteHandoverOrderByIds(ids));
    }


    /**
     * 查询交接信息
     *
     * @param userId 订单创建人
     * @return
     */
    @GetMapping("/getToUser")
    public AjaxResult list(Long userId) {
        HandoverOrder handoverOrder=new HandoverOrder();
        handoverOrder.setStatus(0);
        handoverOrder.setTransfromId(userId);
        List<HandoverOrder> list = handoverOrderService.selectHandoverOrderList(handoverOrder);
        return AjaxResult.success(list);
    }
}
